package com.store.app.activity;


import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.store.app.BaseActivity;
import com.store.app.ExitApplication;
import com.store.app.LocationApplication;
import com.store.app.MainActivity;
import com.store.app.R;
import com.store.app.adapter.BookedClassifyPopAdapter;
import com.store.app.bean.BookedBean;
import com.store.app.bean.EventBusBean;
import com.store.app.bean.ShoppingInfo;
import com.store.app.bean.WypGoodsBean;
import com.store.app.http.Stores;
import com.store.app.http.Submit;
import com.store.app.imlife.utils.ToastTools;
import com.store.app.net.NetRequest;
import com.store.app.net.ifc.IOnHttpListener;
import com.store.app.utils.GoToLogin;
import com.store.app.utils.SettingData;
import com.store.app.utils.Utils;
import com.store.app.widget.BookedOnlinePopupWindow;
import com.store.app.widget.ProgressWebView;
import com.store.app.widget.ShareDialog;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * 嵌网页页面
 * 我要批(給沒交互的使用)
 */
public class WebViewBookedActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener, OnClickListener, IOnHttpListener {
    private TextView tv, tv_right;
    private ProgressWebView webView;
    private String title;
    private String urls = "", id = "";
    private LinearLayout lin_right;
    private ProgressBar progressBar;
    private SwipeRefreshLayout mSwipeLayout;
    private LinearLayout lin_all;
    private RelativeLayout loadfail;
    private LinearLayout lin_loadNull;//加载为空
    private LinearLayout lin_loadfail;  //无网络页面
    private TextView tvReload;
    private BookedOnlinePopupWindow bp_online;
    private PopupWindow mPop;
    private final int POST_SUCC = 8;
    private final int POST_FAIL = 9;
    private String errorMsg;
    private GoToLogin goToLogin;

    private UMImage image;//分享时候的图标
    private String shareTitle;//分享标题
    private String shareText;//分享内容
    private ShareDialog mShareDialog;//分享时候的弹窗
    private UMShareAPI mShareAPI;
    private View tv_Right1;//此页面当分享按钮
    private EditText etSearch;

    public static List<ShoppingInfo> shoppingInfoList;
    private int index = -1;//当前选中下标

    private RelativeLayout relat_classify;//分类relatlayout
    private ImageView img_classify_x;//分类关闭
    private List<String> classifylist = new ArrayList<String>();//分类数据
    private GridView gridclassify;//分类gridview
    private BookedClassifyPopAdapter adapter;// 分类adpter
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case POST_SUCC:
                    dismissProgressDialog();
                    Toast.makeText(WebViewBookedActivity.this, "您的订单已提交，供应商将安排工作人员在24小时内确认订单并协商配送事宜，谢谢合作。", Toast.LENGTH_LONG).show();
                    break;
                case POST_FAIL:
                    dismissProgressDialog();
                    if (!TextUtils.isEmpty(errorMsg)) {
                        Toast.makeText(WebViewBookedActivity.this, errorMsg, Toast.LENGTH_LONG).show();
                    }
                    break;
            }
        }
    };
    private LinearLayout ll_home;
    private LinearLayout ll_type;
    private RelativeLayout ll_shopping_car;
    private LinearLayout ll_order;
    private TextView tv_home_icon;
    private TextView tv_home;
    private TextView tv_type_icon;
    private TextView tv_type;
    private NetRequest netrequest;
    private TextView tv_sell_number;


    public WebViewBookedActivity() {
        super();
    }

    private String from = "";

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        List<Double> nums = new ArrayList<Double>();
//        nums.add(2.0);
//        nums.add(3.3);
//        nums.add(0.2);
//        nums.add(64.5);
//        nums.add(789.0);
//        //设置最大值Max
//        double Max = Collections.max(nums);
//        double min = Collections.min(nums);
//        Log.v("zyl", "Max = " + Max);
//        Log.v("zyl", "min = " + min);
        netrequest = new NetRequest(this);
        shoppingInfoList = new ArrayList<>();
        ExitApplication.getInstance().addActivity(this);
        setContentView(R.layout.activity_wyp);
        initView();
        urls = getIntent().getStringExtra("url");
        title = getIntent().getStringExtra("title");
        try {
            from = getIntent().getStringExtra("from");
        } catch (Exception e) {
            from = "";
        }
        goToLogin = new GoToLogin(this);

        findViews();
        setWebView();
        Log.v("zyl", "current build:" + Build.VERSION.SDK_INT);
        EventBus.getDefault().register(this);

    }

    public void refreshShoppingNumber(){

        int number = getShoppingNumber();
        Log.v("zyl","刷新购物车:"+number);
        if(number == 0){
            Log.v("zyl","数量为0");
            tv_sell_number.setVisibility(View.GONE);
        }else{
            Log.v("zyl","数量为:"+number);
            tv_sell_number.setVisibility(View.VISIBLE);
            tv_sell_number.setText(number+"");
        }
    }
    public void onEvent(List<ShoppingInfo> temList) {
        shoppingInfoList.clear();
        shoppingInfoList.addAll(temList);
        refreshShoppingNumber();
    }

    public void onEvent(EventBusBean eventBus){
        Log.v("zyl","onEvent 刷新数量");
        if(eventBus.type == 209){
            refreshShoppingNumber();
        }
    }

    public static int getShoppingNumber() {
        int number = 0;
        if (shoppingInfoList != null) {
            for (int i = 0; i < shoppingInfoList.size(); i++) {
                number += shoppingInfoList.get(i).getBookedBeanList().size();
            }
        }
        return number;
    }

//    public void onEvent2(WypGoodsBean bookedBean) {
//        String goods_id = bookedBean.getGoods_id();
//        String warehouse = bookedBean.getWarehouse();
//        String key = goods_id + warehouse;
//        //购物车
//        Map<String, List<WypGoodsBean>> map1 = new LinkedHashMap<String, List<WypGoodsBean>();
//        List<WypGoodsBean> bookeList = map1.get(key);
//        if (bookeList == null) {
//            bookeList = new ArrayList<WypGoodsBean>();
//        }
//        bookeList.add(bookedBean);
//
//        map1.put(key, bookeList);
//
//
//    }

//    public void onEvent(WypGoodsBean bookedBean) {
//
//        //商品所属供应商
//        String temSupId = bookedBean.getSupplier_id();
//        //商品所属仓位
//        String tempWarehouse = bookedBean.getWarehouse();
//        //商品的所属标准
//        String sigleStation = temSupId + tempWarehouse;
//        //遍历父节点中的 仓位+标准
//        boolean ifExist = false;
//        for (int i = 0; i < shoppingInfoList.size(); i++) {
//            //发现商品所属该目录，则遍历是否该子集下是否有此商品，如果有，则判断规格是否一致，否则直接商品数量+1，如果不存在此商品。则直接添加商品
//            if ((shoppingInfoList.get(i).getSupplierId() + shoppingInfoList.get(i).getWarehouse()).equals(sigleStation)) {
//                ifExist = true;
//                List<WypGoodsBean> temList = shoppingInfoList.get(i).getBookedBeanList();
//                boolean ifExistBean = false;
//                for (int j = 0; j < temList.size(); j++) {
//                    //判断到时同一商品
//                    if (temList.get(j).getGoods_id().equals(bookedBean.getGoods_id())) {
//                        //已经存在此商品
//                        ifExistBean = true;
//                        //判断规格是否相同
//                        String goods_stock_id = bookedBean.getSpecificationsBeanList().get(bookedBean.getChooseIndexSpeci()).getGoods_stock_id();
//                        String temGoods_stock_id = temList.get(j).getSpecificationsBeanList().get(temList.get(j).getChooseIndexSpeci()).getGoods_stock_id();
//                        //规格相同直接添加数量，后期需要判断添加数量时候是否超过库存
//                        if (goods_stock_id.equals(temGoods_stock_id)) {
//                            //如果存在此商品，并且规格相同，则直接添加数量
//                            int currentCount = shoppingInfoList.get(i).getBookedBeanList().get(j).getBuyCount();
//                            int addCount = bookedBean.getBuyCount();
//                            Log.v("zyl", "currentCount：" + currentCount);
//                            Log.v("zyl", "addCount：" + addCount);
//                            temList.get(j).setBuyCount(currentCount + addCount);
//                        }
//                        //规格不同，则作为新商品添加
//                        else {
//                            shoppingInfoList.get(i).getBookedBeanList().add(bookedBean);
//                        }
//                    }
//                }
//                if (!ifExistBean) {
//                    shoppingInfoList.get(i).getBookedBeanList().add(bookedBean);
//                }
//            }
//        }
//
//        if (!ifExist) {
//
//        } else {
//            ShoppingInfo shoppingInfo = new ShoppingInfo();
//            shoppingInfo.setSupplierId(bookedBean.getSupplier_id());
//            shoppingInfo.setSupplierName(bookedBean.getSupplier());
//            List<WypGoodsBean> bookedBeanList = new ArrayList<>();
//            bookedBeanList.add(bookedBean);
//            shoppingInfo.setBookedBeanList(bookedBeanList);
//            shoppingInfo.setWarehouse(bookedBean.getWarehouse());
//            shoppingInfoList.add(shoppingInfo);
//        }
//    }


    //    public void onEvent(WypGoodsBean bookedBean) {
//        String temSupId = bookedBean.getSupplier_id();
//        String tempWarehouse = bookedBean.getWarehouse();
//        boolean ifExist = false;
//        //判断购车里面是否已经存在了这个供应商了
//        for (int i = 0; i < shoppingInfoList.size(); i++) {
//            //与每一个(供应商相+仓位)匹配，判断是否已经有此父节点了
//            if (shoppingInfoList.get(i).getSupplierId().equals(temSupId) && shoppingInfoList.get(i).getWarehouse().equals(tempWarehouse)) {
//                ifExist = true;//
//                //发现已经存在该供应商了，取出在该供应商购买过的商品列表，看看是否存在
//                boolean ifExistBean = false;
//                for (int j = 0; j < shoppingInfoList.get(i).getBookedBeanList().size(); j++) {
//                    if (shoppingInfoList.get(i).getBookedBeanList().get(j).getGoods_id().equals(bookedBean.getGoods_id())) {
//                        ifExistBean = true;
//                        //如果存在此商品，则当前商品的数量加上新的数量
//                        int currentCount = shoppingInfoList.get(i).getBookedBeanList().get(j).getBuyCount();
//                        int addCount = bookedBean.getBuyCount();
//                        Log.v("zyl", "currentCount：" + currentCount);
//                        Log.v("zyl", "addCount：" + addCount);
//                        //如果当前数量加上新增数量超过限购数量，则直接显示限购是数量
//                        int maxCount = 0;
//                        if (TextUtils.isEmpty(bookedBean.getMax_buy_qty())) {
//                            maxCount = 0;
//                        } else {
//                            maxCount = Integer.parseInt(bookedBean.getMax_buy_qty());
//                        }
//                        Log.v("zyl", "maxCount：" + maxCount);
//
//                        int sale_qty = Integer.parseInt(bookedBean.getSale_qty());//得到库存
//                        if (sale_qty == 0) {
//                            ToastTools.showShort(WebViewBookedActivity.this, "库存不足");
//                            return;
//                        }
//                        if (maxCount > sale_qty) {
//                            ToastTools.showShort(WebViewBookedActivity.this, "限购大于库存，无法加入购物车！");
//                            return;
//                        }
//                        if (currentCount + addCount > sale_qty) {
//                            ToastTools.showShort(WebViewBookedActivity.this, "库存不足");
//                            return;
//                        }
//
//                        if (currentCount + addCount >= maxCount && maxCount != 0) {
//                            shoppingInfoList.get(i).getBookedBeanList().get(j).setBuyCount(maxCount);
//                        } else {
//                            shoppingInfoList.get(i).getBookedBeanList().get(j).setBuyCount(currentCount + addCount);
//                        }
//                    }
//                }
//                //如果已经存在，之前已经加数量了，若不存在，则直接添加商品即可
//                if (!ifExistBean) {
//                    shoppingInfoList.get(i).getBookedBeanList().add(bookedBean);
//                }
//            }
//        }
//        //判断得到是否已经有此供应商了
//        if (ifExist) {
//            //已经存在,则之前已经将商品添加到购物车了，如果不存在，则新添加供应商，并添加商品
//        }
//        //不存在
//        else {
//            int sale_qty = Integer.parseInt(bookedBean.getSale_qty());//得到库存
//            //如果当前数量加上新增数量超过限购数量，则直接显示限购是数量
//            int maxCount = 0;
//
//            if (TextUtils.isEmpty(bookedBean.getMax_buy_qty())) {
//                maxCount = 0;
//            } else {
//                maxCount = Integer.parseInt(bookedBean.getMax_buy_qty());
//            }
//
//            if (sale_qty == 0) {
//                ToastTools.showShort(WebViewBookedActivity.this, "库存不足");
//                return;
//            }
////            if(maxCount>sale_qty){
////                ToastTools.showShort(WebViewBookedActivity.this, "限购大于库存，无法加入购物车！");
////                return;
////            }
//            if (bookedBean.getBuyCount() > sale_qty) {
//                ToastTools.showShort(WebViewBookedActivity.this, "库存不足");
//                return;
//            }
//
//
//            ShoppingInfo shoppingInfo = new ShoppingInfo();
//            shoppingInfo.setSupplierId(bookedBean.getSupplier_id());
//            shoppingInfo.setSupplierName(bookedBean.getSupplier());
//            List<BookedBean> bookedBeanList = new ArrayList<>();
//            bookedBeanList.add(bookedBean);
//            shoppingInfo.setBookedBeanList(bookedBeanList);
//            shoppingInfoList.add(shoppingInfo);
//        }
//
//        ToastTools.showShort(WebViewBookedActivity.this, "添加到购物车成功!");
//        //此时商品已经添加好了，判断下累加之后的数量是否大于库存，如果是，则显示库存数量就好了。
//
//
////        Log.v("zyl", "此时所有数据shoppingInfoList.size：" + shoppingInfoList.size());
////        for (int i = 0; i < shoppingInfoList.size(); i++) {
////            String name = shoppingInfoList.get(i).getSupplierName();
////            Log.v("zyl", "name:" + name);
////            List<BookedBean> tep = shoppingInfoList.get(i).getBookedBeanList();
////            for (int j = 0; j < tep.size(); j++) {
////                Log.v("zyl", "tep name:" + tep.get(j).getTitle());
////                Log.v("zyl", "tep count:" + tep.get(j).getBuyCount());
////            }
////        }
//    }
    public void onEvent(WypGoodsBean bookedBean) {
        String temSupidAndwarehouse = bookedBean.getSupidAndwarehouse();
        Log.v("zyl", "新添加商品的temSupidAndwarehouse：" + temSupidAndwarehouse);
        String temGoodsidAndstockId = bookedBean.getGoodsidAndstockId();
        Log.v("zyl", "新添加商品的temGoodsidAndstockId：" + temGoodsidAndstockId);
        boolean ifExist = false;
        //判断购车里面是否已经存在了这个供应商了
        for (int i = 0; i < shoppingInfoList.size(); i++) {
            //与每一个(供应商相+仓位)匹配，判断是否已经有此父节点了
            if (shoppingInfoList.get(i).getSupidAndwarehouse().equals(temSupidAndwarehouse)) {
                ifExist = true;//
                //发现已经存在该供应商了，取出在该供应商购买过的商品列表，看看是否存在
                boolean ifExistBean = false;
                Log.v("zyl", "shoppingInfoList.get(i).getBookedBeanList().size():" + shoppingInfoList.get(i).getBookedBeanList().size());
                for (int j = 0; j < shoppingInfoList.get(i).getBookedBeanList().size(); j++) {
                    //商品id跟规格都一样的情况下
                    Log.v("zyl", "shoppingInfoList.get(i).getBookedBeanList().get(j).getGoodsidAndstockId():" + j + "===" + shoppingInfoList.get(i).getBookedBeanList().get(j).getGoodsidAndstockId());
                    Log.v("zyl", "bookedBean.getGoodsidAndstockId():" + j + "===" + bookedBean.getGoodsidAndstockId());
                    if (shoppingInfoList.get(i).getBookedBeanList().get(j).getGoodsidAndstockId().equals(bookedBean.getGoodsidAndstockId())) {
                        Log.v("zyl", "商品规格一样");
                        ifExistBean = true;
                        //如果存在此商品，则当前商品的数量加上新的数量
                        int currentCount = shoppingInfoList.get(i).getBookedBeanList().get(j).getBuyCount();
                        int addCount = bookedBean.getBuyCount();
                        Log.v("zyl", "currentCount：" + currentCount);
                        Log.v("zyl", "addCount：" + addCount);
                        //如果当前数量加上新增数量超过限购数量，则直接显示限购是数量(但是要判断下余数情况)
                        int maxCount = 0;
                        if (TextUtils.isEmpty(bookedBean.getMax_buy_qty())) {
                            maxCount = 0;
                        } else {
                            maxCount = Integer.parseInt(bookedBean.getMax_buy_qty());
                        }
                        Log.v("zyl", "maxCount：" + maxCount);

                        int sale_qty = Integer.parseInt(bookedBean.getSpecificationsBeanList().get(bookedBean.getChooseIndexSpeci()).getSale_qty());//得到库存
                        if (sale_qty == 0) {
                            ToastTools.showShort(WebViewBookedActivity.this, "库存不足");
                            return;
                        }
//                        if (maxCount > sale_qty) {
//                            ToastTools.showShort(WebViewBookedActivity.this, "限购大于库存，无法加入购物车！");
//                            return;
//                        }
                        Log.v("zyl", "currentCount + addCount:" + (currentCount + addCount));
                        Log.v("zyl", "sale_qty:" + sale_qty);
                        if (currentCount + addCount > sale_qty) {
                            ToastTools.showShort(WebViewBookedActivity.this, "库存不足");
                            return;
                        }

                        if (currentCount + addCount >= maxCount && maxCount != 0) {

                            //最低起订量
                            int minCount = Integer.parseInt(bookedBean.getMin_buy_qty());
                            int yushu = maxCount % minCount;
                            if (yushu == 0) {
                                shoppingInfoList.get(i).getBookedBeanList().get(j).setBuyCount(maxCount);
                            } else {
                                shoppingInfoList.get(i).getBookedBeanList().get(j).setBuyCount(maxCount - yushu);
                            }

                            //看看

                        } else {
                            shoppingInfoList.get(i).getBookedBeanList().get(j).setBuyCount(currentCount + addCount);
                        }
                    }
                    //只有商品id一样，规格不一样的情况下，也是要判断是否已经存在，存在则添加数量，不存在直接添加
                    else {
                        Log.v("zyl", "直接添加");
//                      shoppingInfoList.get(i).getBookedBeanList().add(bookedBean);
                    }
                }
                //如果已经存在，之前已经加数量了，若不存在，则直接添加商品即可
                if (!ifExistBean) {
                    shoppingInfoList.get(i).getBookedBeanList().add(bookedBean);
                }
            }
        }
        //判断得到是否已经有此供应商了
        if (ifExist) {
            //已经存在,则之前已经将商品添加到购物车了，如果不存在，则新添加供应商，并添加商品
        }
        //不存在
        else {
            int sale_qty = Integer.parseInt(bookedBean.getSale_qty());//得到库存
            //如果当前数量加上新增数量超过限购数量，则直接显示限购是数量
            int maxCount = 0;

            if (TextUtils.isEmpty(bookedBean.getMax_buy_qty())) {
                maxCount = 0;
            } else {
                maxCount = Integer.parseInt(bookedBean.getMax_buy_qty());
            }

            if (sale_qty == 0) {
                ToastTools.showShort(WebViewBookedActivity.this, "库存不足");
                return;
            }
//            if(maxCount>sale_qty){
//                ToastTools.showShort(WebViewBookedActivity.this, "限购大于库存，无法加入购物车！");
//                return;
//            }
            if (bookedBean.getBuyCount() > sale_qty) {
                ToastTools.showShort(WebViewBookedActivity.this, "库存不足");
                return;
            }


            ShoppingInfo shoppingInfo = new ShoppingInfo();
            shoppingInfo.setSupplierId(bookedBean.getSupplier_id());
            shoppingInfo.setSupplierName(bookedBean.getSupplier());
            shoppingInfo.setSupidAndwarehouse(bookedBean.getSupidAndwarehouse());
            shoppingInfo.setWarehouse(bookedBean.getWarehouse());
            Log.v("zyl", "添加进去的仓位为：" + bookedBean.getWarehouse_id());
            Log.v("zyl", "添加进去的bean的GoodsidAndstockId为：" + bookedBean.getGoodsidAndstockId());
            shoppingInfo.setWarehouse_id(bookedBean.getWarehouse_id());
            List<WypGoodsBean> bookedBeanList = new ArrayList<>();
            bookedBeanList.add(bookedBean);
            shoppingInfo.setBookedBeanList(bookedBeanList);
            shoppingInfoList.add(shoppingInfo);
        }

        ToastTools.showShort(WebViewBookedActivity.this, "添加到购物车成功!");
        //此时商品已经添加好了，判断下累加之后的数量是否大于库存，如果是，则显示库存数量就好了。


        Log.v("zyl", "此时所有数据shoppingInfoList.size：" + shoppingInfoList.size());
        for (int i = 0; i < shoppingInfoList.size(); i++) {
            String name = shoppingInfoList.get(i).getSupplierName();
            Log.v("zyl", "name:" + name);
            List<WypGoodsBean> tep = shoppingInfoList.get(i).getBookedBeanList();
            Log.v("zyl", "shoppingInfoList" + tep.size());
            for (int j = 0; j < tep.size(); j++) {
                Log.v("zyl", "tep id+guige:" + tep.get(j).getGoodsidAndstockId());
                Log.v("zyl", "tep name:" + tep.get(j).getTitle());
                Log.v("zyl", "tep count:" + tep.get(j).getBuyCount());
                Log.v("zyl", "tep guige:" + tep.get(j).getSpecificationsBeanList().get(tep.get(j).getChooseIndexSpeci()).getDesc1());
            }
        }
    }

    private void setWebView() {
        webView.clearCache(true);
        Log.v("zyl","urls:"+urls);
        webView.loadUrl(urls);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setLoadsImagesAutomatically(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDefaultTextEncodingName("utf-8");
        webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);//设置不使用缓存
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        webView.setWebViewClient(new WebViewClient1()
//			@Override
//			public boolean shouldOverrideUrlLoading(WebView view, String url) {
//				Log.v("zyl", "shouldOverrideUrlLoading:" + url);
//				if (url.contains("/wholesale/detail")) {
//					Log.v("zyl", "包含");
//					Intent intent = new Intent (WebViewBookedActivity.this,WebViewBooked2Activity.class);
//					intent.putExtra("url",  url);
//					intent.putExtra("title", "我要批");
//					startActivity(intent);
//
//				} else {
//					Log.v("zyl", "不包含");
//				}
//				if (url.startsWith("http:") || url.startsWith("https:")) {
//					return false;
//				}
//
//				// Otherwise allow the OS to handle things like tel, mailto, etc.
//				try {
//					Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
//					startActivity(intent);
//				} catch (Exception e) {
//				}
//				return true;
//			}
        );
        webView.setWebChromeClient(new WebChromeClient1());
        webView.addJavascriptInterface(new JSInterface(), "jsObj");


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.public_ll_right:
                if ("wyp".equals(from)) {
                    Intent intent = new Intent(WebViewBookedActivity.this, TheSingleOrderActivity.class);
                    intent.putExtra("showFragmentIndex", "1");
                    startActivity(intent);
//                    Intent intent = new Intent(WebViewBookedActivity.this, WebViewSearchActivity.class);
//                    startActivity(intent);
//					String[] mPermissionList = new String[]{Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.CALL_PHONE,Manifest.permission.READ_LOGS,Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.SET_DEBUG_APP,Manifest.permission.SYSTEM_ALERT_WINDOW,Manifest.permission.GET_ACCOUNTS};
//					ActivityCompat.requestPermissions(WebViewBookedActivity.this, mPermissionList, 100);
                } else if ("cjf".equals(from)) {
//                    Intent intent = new Intent(WebViewBookedActivity.this, WebViewBooked2Activity.class);
//                    intent.putExtra("title", "领了么");//==>淘淘领
//                    intent.putExtra("url", SettingData.FREE_HELP);
//                    startActivity(intent);

                } else {
                    finish();
                }
                break;
            case R.id.tv_right1:

                //跳转到订单页面，默认显示领样
                Intent intent = new Intent(WebViewBookedActivity.this, TheSingleOrderActivity.class);
                intent.putExtra("showFragmentIndex", "2");
                startActivity(intent);

                /**
                 * 分享功能，隐藏
                 */
//                mShareDialog = new ShareDialog(WebViewBookedActivity.this, listener);
//                mShareDialog.show();
                break;

            case R.id.ll_home://首页
                index = 0;
                refreshMainIndex();
                dismissClassify();
                break;
            case R.id.ll_type://分类
                index = 1;
                refreshMainIndex();
                showClassify();//打开分类
                break;
            case R.id.ll_shopping_car://
                index = 0;
                refreshMainIndex();
                dismissClassify();
                if (shoppingInfoList.size() == 0) {
                    ToastTools.showShort(WebViewBookedActivity.this, "请添加商品到购物车！");
                    return;
                }
                Intent intent2 = new Intent(WebViewBookedActivity.this, ShoppingCarActivity.class);
                Log.v("zyl", "shoppingInfoList size:" + shoppingInfoList.size());
                intent2.putExtra("listData", (Serializable) shoppingInfoList);
                startActivity(intent2);
                break;
            case R.id.ll_order://订单
                index = 0;
                refreshMainIndex();
                dismissClassify();
                Intent intent3 = new Intent(WebViewBookedActivity.this, TheSingleOrderActivity.class);
                intent3.putExtra("showFragmentIndex", "1");
                startActivity(intent3);
                break;
            case R.id.bookedclassify_x://分类空白地方
                index = 0;
                refreshMainIndex();
                dismissClassify();
                break;
        }
    }

    private void initView() {
        ll_home = (LinearLayout) findViewById(R.id.ll_home);
        ll_type = (LinearLayout) findViewById(R.id.ll_type);
        ll_shopping_car = (RelativeLayout) findViewById(R.id.ll_shopping_car);
        ll_order = (LinearLayout) findViewById(R.id.ll_order);
        ll_home.setOnClickListener(this);
        ll_type.setOnClickListener(this);
        ll_shopping_car.setOnClickListener(this);
        ll_order.setOnClickListener(this);
        tv_home_icon = (TextView) findViewById(R.id.tv_home_icon);
        tv_home = (TextView) findViewById(R.id.tv_home);
        tv_type_icon = (TextView) findViewById(R.id.tv_type_icon);
        tv_type = (TextView) findViewById(R.id.tv_type);
        relat_classify = (RelativeLayout) findViewById(R.id.bookedclassify_relat);
        img_classify_x = (ImageView) findViewById(R.id.bookedclassify_x);
        img_classify_x.setOnClickListener(this);
        gridclassify = (GridView) findViewById(R.id.bookedclassify_gridview);

//        adapter = new BookedClassifyPopAdapter(this, list);
//        gridclassify.setAdapter(adapter);
        tv_sell_number = (TextView) findViewById(R.id.tv_sell_number);
    }

    final class JSInterface {

        private Handler handler = new Handler();
        @JavascriptInterface
        public void goToWypCategory(final String category) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Log.v("zyl","goToWypCategory");
                    Intent intent = new Intent(WebViewBookedActivity.this, WebViewWYPSearchActivity.class);
                    String url = SettingData.http + SettingData.wypURL_classify + Stores.area_id + "&category=" + category;
                    intent.putExtra("url", url);
                    startActivity(intent);
                }
            }, 0);
        }

        @JavascriptInterface
        public void storeGetFreeSucc() {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Log.v("zyl", "店东领取成功，跳转到订单页面");
                    Intent intent = new Intent(WebViewBookedActivity.this, TheSingleOrderActivity.class);
                    intent.putExtra("showFragmentIndex", "2");//2代表免费领样的Fragment
                    startActivity(intent);
                }
            }, 1500);
        }

        //打开广告页
        @JavascriptInterface
        public void openAdLayer(final String jsonData) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    Log.v("zyl", "openAdLayer jsonData:" + jsonData);
                    try {
                        JSONObject jsonObject = new JSONObject(jsonData);
                        String url = jsonObject.getString("url");
                        Intent intent = new Intent(WebViewBookedActivity.this, WebViewAdActivity.class);
                        intent.putExtra("url", url);
                        startActivity(intent);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

            });
        }
//        @JavascriptInterface
//        public void buyGoods(final String string) {
//            handler.post(new Runnable() {
//                @Override
//                public void run() {
//
//                    String goods_id = string;
//                    bp_online = new BookedOnlinePopupWindow(goods_id);
//                    mPop = bp_online.getPopupWindow(WebViewBookedActivity.this);
//                    WindowManager.LayoutParams lp = getWindow().getAttributes();
//                    lp.alpha = 0.7f;
//                    getWindow().setAttributes(lp);
//                    mPop.showAtLocation(lin_all, Gravity.BOTTOM, 0, 0);
//                    bp_online.setonDisMissListener(new BookedOnlinePopupWindow.DisMissListener() {
//                        @Override
//                        public void dissmiss() {
//                            WindowManager.LayoutParams lp = getWindow().getAttributes();
//                            lp.alpha = 1f;
//                            getWindow().setAttributes(lp);
//                        }
//                    });
//                    bp_online.setonPostListener(new BookedOnlinePopupWindow.PostListener() {
//                        @Override
//                        public void post(final BookedBean bookedBean, final int num, final String money) {
//
//                            if (Integer.parseInt(bookedBean.getSale_qty()) < num) {
//                                Toast.makeText(WebViewBookedActivity.this, "库存不足！", Toast.LENGTH_SHORT).show();
//                                return;
//                            }
//                            String s_pay_way = bookedBean.getPayment_way();
//                            if (s_pay_way.equals("online")) {
//                                Intent intent = new Intent(WebViewBookedActivity.this, ConfirmPaymentActivity.class);
//                                intent.putExtra("bean", bookedBean);
//                                intent.putExtra("num", num);
//                                intent.putExtra("money", money);
//                                startActivity(intent);
//                                mPop.dismiss();
//                            } else if (s_pay_way.equals("offline")) {
////                                AlertDialog.Builder builder = new AlertDialog.Builder(WebViewBookedActivity.this);
////                                builder.setMessage("您确认要提交该订单货到付款吗？")
////                                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
////                                            @Override
////                                            public void onClick(DialogInterface dialog, int which) {
////                                                mPop.dismiss();
////                                            }
////                                        });
////                                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
////                                    @Override
////                                    public void onClick(DialogInterface dialog, int which) {
////                                        mPop.dismiss();
////                                        Toast.makeText(WebViewBookedActivity.this, "订单提交中...", Toast.LENGTH_SHORT).show();
////                                        new PostGoodsInfo(num, money, bookedBean).start();
////                                    }
////                                });
////                                builder.show();
//                            }
//                        }
//                    });
//                    return;
//                }
//            });
//
//        }

        @JavascriptInterface
        public void scan(final String string) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    Log.v("zyl", "scan:" + string);
                    try {
                        JSONObject jsonObject = new JSONObject(string);
                        String goods_code = jsonObject.getString("goods_code");
                        String goods_url = jsonObject.getString("goods_url");
                        String amount = jsonObject.getString("amount");
                        Intent intent = new Intent(WebViewBookedActivity.this, FreeScanActivity.class);
                        intent.putExtra("goods_code", goods_code);
                        intent.putExtra("goods_url", goods_url);
                        intent.putExtra("amount", amount);
                        startActivity(intent);
                    } catch (Exception e) {
                    }

                }

            });
        }

        // 供JS调用
        public void logout(String str) {

        }
    }

    public void showLoadResult(int state) {
        //无网络情况
        if (state == 1) {
            loadfail.setVisibility(View.VISIBLE);
            lin_loadfail.setVisibility(View.VISIBLE);
            lin_loadNull.setVisibility(View.GONE);
        }//无数据情况
        else if (state == 2) {
            Log.v("zyl", "无数据");
            loadfail.setVisibility(View.VISIBLE);
            lin_loadfail.setVisibility(View.GONE);
            lin_loadNull.setVisibility(View.VISIBLE);
        }//都不显示
        else {
            loadfail.setVisibility(View.GONE);
        }
    }

    public class WebViewClient1 extends WebViewClient {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {                 // Handle the error
            Log.v("zyl", "onReceivedError网络加载不出来");
//            webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);

            //停止vebview所有操作
            webView.onPause();
            webView.pauseTimers();

//			lin_loadfail.setVisibility(View.VISIBLE);
            showLoadResult(1);
//			Toast.makeText(WebViewBookedActivity.this,"description:"+description,Toast.LENGTH_SHORT).show();
        }


        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.v("zyl", "变化的URL:" + url);
            if (url.contains("wholesale/detail")) {
                Log.v("zyl", "包含");
                Intent intent = new Intent(WebViewBookedActivity.this, WebViewBookedDetailsActivity.class);
                intent.putExtra("url", url);
                intent.putExtra("title", "我要批");
                startActivity(intent);
                return true;
            } else if (url.contains("free/detail")) {
                Intent intent = new Intent(WebViewBookedActivity.this, FreeDetailsWebViewActivity.class);
                intent.putExtra("url", url);
                intent.putExtra("title", "淘淘领");//领了么==>淘淘领
                startActivity(intent);
                return true;
            } else {
                Log.v("zyl", "不包含");
            }
            if (url.startsWith("http:") || url.startsWith("https:")) {
                return false;
            }

            // Otherwise allow the OS to handle things like tel, mailto, etc.
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
            } catch (Exception e) {

            }
            return true;
//			view.loadUrl(url);
//			return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            Log.v("zyl", "onPageStart:" + url);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (url.startsWith("http")) {
                urls = url;
            }
        }

    }

    public class WebChromeClient1 extends WebChromeClient {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            Log.v("zyl", "加载进度：" + newProgress);
            if (newProgress == 100) {
                progressBar.setVisibility(View.GONE);
            } else {
                if (progressBar.getVisibility() == View.GONE)
                    progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(newProgress);
            }
            super.onProgressChanged(view, newProgress);
        }


    }

    public void onPause() {//继承自Activity
        super.onPause();
        webView.onPause();

        webView.pauseTimers();
        if (isFinishing()) {
            Log.v("zyl", "isFinishing");
            webView.loadUrl("about:blank");
            setContentView(new FrameLayout(this));
        }
    }

    public void onResume() {//继承自Activity
        super.onResume();
        webView.onResume();
        webView.resumeTimers();
        refreshMainIndex();

    }

    public void refreshMainIndex() {
        if (index == 0) {
            tv_home_icon.setBackgroundResource(R.drawable.pic_icon_home);
            tv_home.setTextColor(Color.parseColor("#ff0000"));
            tv_type_icon.setBackgroundResource(R.drawable.pic_icon_type_black);
            tv_type.setTextColor(Color.parseColor("#666666"));

        } else if (index == 1) {
            tv_home_icon.setBackgroundResource(R.drawable.pic_icon_home_black);
            tv_home.setTextColor(Color.parseColor("#666666"));
            tv_type_icon.setBackgroundResource(R.drawable.pic_icon_type);
            tv_type.setTextColor(Color.parseColor("#ff0000"));
        }
    }

    private void findViews() {
        etSearch = (EditText) findViewById(R.id.et_search);

        tv_Right1 = findViewById(R.id.tv_right1);
        tv_Right1.setOnClickListener(this);
        lin_right = (LinearLayout) findViewById(R.id.public_ll_right);
//		lin_right.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
////				if(title.equals("免费领")){
////					Log.v("zyl","是惠金币类型");
////					startActivity(new Intent(WebViewBookedActivity.this,GoldBalanceActivity.class));
////				}else{
////					跳到搜索页面
//					if("wyp".equals(from)){
//						Intent intent = new Intent(WebViewBookedActivity.this,WebViewSearchActivity.class);
//						startActivity(intent);
//					}
//
////					finish();
////				}
//			}
//		});
        lin_right.setOnClickListener(this);
        tv_right = (TextView) findViewById(R.id.public_tv_right);
//		if(title.equals("免费领")){
//			tv_right.setText("金币明细");
//		}else{
//			tv_right.setText("关闭");
//		}

        if ("wyp".equals(from)) {
            tv_right.setText("");
            tv_right.setBackgroundResource(R.drawable.pic_new_older_icon);
        } else if ("cjf".equals(from)) {
            tv_right.setVisibility(View.GONE);
            tv_right.setText("");
            tv_Right1.setVisibility(View.VISIBLE);
            tv_Right1.setBackgroundResource(R.drawable.pic_new_older_icon);
        } else {
//            tv_right.setText("关闭");
            tv_right.setBackgroundResource(R.drawable.pic_icon_close_x);
        }
        progressBar = (ProgressBar) findViewById(R.id.progressbar);
        loadfail = (RelativeLayout) findViewById(R.id.loadfail);

        lin_loadfail = (LinearLayout) findViewById(R.id.ll_load_fail);//无网络
        lin_loadNull = (LinearLayout) findViewById(R.id.ll_load_null);//无网络
        tvReload = (TextView) findViewById(R.id.tv_reload);
        tvReload.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Utils.isFastClick()) {
                    return;
                }
                showLoadResult(3);
                webView.clearCache(true);
                webView.clearHistory();
                webView.clearFormData();
                webView.loadUrl(urls);
            }
        });
        lin_all = (LinearLayout) findViewById(R.id.lin_all);
        webView = (ProgressWebView) findViewById(R.id.onlcon_web);
        webView.setContext(this);
        etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                Log.v("zyl", "onEditorAction :" + actionId);
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    String temUrl = SettingData.http + "/openapi/h5/b/wholesale/search?area_id=" + Stores.area_id + "&channel=android&keyword=" + etSearch.getText().toString().trim() + "";
//                    webView.loadUrl(urls);

                    Intent intent6 = new Intent();
                    intent6.setClass(WebViewBookedActivity.this, WebViewWYPSearchActivity.class);
                    intent6.putExtra("url", temUrl);
                    startActivity(intent6);
                    etSearch.setText("");
                    return true;
                }
                return false;
            }
        });
        findViewById(R.id.public_ll_return).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (webView.canGoBack() && !"about:blank".equals(webView.getUrl())) {
                    webView.goBack();// 返回前一个页面
                } else {
                    finish();
                }
            }
        });
//		lin_loadfail.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				lin_loadfail.setVisibility(View.GONE);
//				webView.clearCache(true);
//				webView.clearHistory();
//				webView.clearFormData();
//				webView.loadUrl(urls);
//			}
//		});

        mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.sw);
        mSwipeLayout.setOnRefreshListener(this);

        mShareAPI = UMShareAPI.get(this);
        image = new UMImage(WebViewBookedActivity.this, R.drawable.pic_icon_share_logo);
        shareTitle = "天上真的会掉馅饼哦,你敢来,我敢送!";
        shareText = "欢迎光临每天惠旗下门店咨询";


        gridclassify.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(WebViewBookedActivity.this, WebViewWYPSearchActivity.class);
                String url = SettingData.http + SettingData.wypURL_classify + Stores.area_id + "&category=" + classifylist.get(position);
                intent.putExtra("url", url);
                startActivity(intent);
                relat_classify.setVisibility(View.GONE);
                index = 0;
                refreshMainIndex();
            }
        });
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack() && !"about:blank".equals(webView.getUrl())) {
            webView.goBack();// 返回前一个页面
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    @Override
    public void onRefresh() {
        setWebView();
        mSwipeLayout.setRefreshing(false);
    }

    /**
     * 订单提交
     */
    public class PostGoodsInfo extends Thread {
        private int num;
        private String money;
        private BookedBean bean;

        public PostGoodsInfo(int num, String money, BookedBean bean) {
            this.num = num;
            this.money = money;
            this.bean = bean;
        }

        public void run() {
            try {
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                DecimalFormat df = new DecimalFormat("######0.00");
                double d_maker = Double.parseDouble(bean.getMarket_price()) * num;
                double d_discount = Double.parseDouble(money);
                double free = d_maker - d_discount;

                JSONObject paramstwo = new JSONObject();
                paramstwo.put("goods_id", bean.getGoods_id());
                paramstwo.put("qty", num + "");
                paramstwo.put("goods_unit", bean.getGoods_unit());
                paramstwo.put("sale_price", df.format(d_maker));
                paramstwo.put("total_fee", money);
                paramstwo.put("discount_fee", df.format(free));
                //新增接口
                paramstwo.put("goods_title", bean.getTitle());
                paramstwo.put("goods_pic_info", bean.getPic_info());

                JSONObject paramsone = new JSONObject();
                paramsone.put("desc1", bean.getTitle());
                paramsone.put("item_num", "1");
                paramsone.put("total_fee", money);
                paramsone.put("discount_fee", df.format(free));
                paramsone.put("sale_fee", df.format(d_maker));
                paramsone.put("member_id", MainActivity.member_id);
                paramsone.put("member_type_key", "stores");
                paramsone.put("delivery_address", Stores.address);
                paramsone.put("contact_person", Stores.contact_person);
                paramsone.put("contact_tel", Stores.contact_tel);
                paramsone.put("ps_goods", paramstwo.toString());

                params.add(new BasicNameValuePair("params", paramsone.toString()));
                params.add(new BasicNameValuePair("service", "order.psOrderAdd"));
                params.add(new BasicNameValuePair("user_token", MainActivity.user_token));
                String sign = Submit.genPackageSignUser(params);
                params.add(new BasicNameValuePair("sign", sign));
                JSONObject obj = Submit.submit(params, Stores.http + "/openapi/opsorder");
                String result = obj.getString("rsp_code");
                if (result.equals("succ")) {
                    Message msg = Message.obtain();
                    msg.what = POST_SUCC;
                    handler.sendMessage(msg);
                } else {
                    if (goToLogin.setGoToLogin(obj)) {

                    } else {
                        Message msg = Message.obtain();
                        msg.what = POST_FAIL;
                        errorMsg = obj.getString("error_msg");
                        handler.sendMessage(msg);
                    }
                }
            } catch (Exception e) {
                Message msg = Message.obtain();
                msg.what = POST_FAIL;
                handler.sendMessage(msg);
            }
        }
    }

    ShareDialog.OnShareClickListener listener = new ShareDialog.OnShareClickListener() {
        @Override
        public void FriendCircle(View v) {
            new ShareAction(WebViewBookedActivity.this).setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE).setCallback(umShareListener)
                    .withTitle(shareTitle)
                    .withMedia(image)
                    .withText(shareText)
                    .withTargetUrl(LocationApplication.shareURL)
                    .share();
            mShareDialog.dismiss();
        }

        @Override
        public void WeChatFriends(View v) {
            new ShareAction(WebViewBookedActivity.this).setPlatform(SHARE_MEDIA.WEIXIN).setCallback(umShareListener)
                    .withTitle(shareTitle)
                    .withMedia(image)
                    .withText(shareText)
                    .withTargetUrl(LocationApplication.shareURL)
                    .share();
            mShareDialog.dismiss();
        }

        @Override
        public void QQFriends(View v) {
            new ShareAction(WebViewBookedActivity.this).setPlatform(SHARE_MEDIA.QQ).setCallback(umShareListener)
                    .withTitle(shareTitle)
                    .withMedia(image)
                    .withText(shareText)
                    .withTargetUrl(LocationApplication.shareURL)
                    .share();
            mShareDialog.dismiss();

        }

        @Override
        public void QQZone(View v) {
            new ShareAction(WebViewBookedActivity.this).setPlatform(SHARE_MEDIA.QZONE).setCallback(umShareListener)
                    .withTitle(shareTitle)
                    .withMedia(image)
                    .withText(shareText)
                    .withTargetUrl(LocationApplication.shareURL)
                    .share();
            mShareDialog.dismiss();
        }

        @Override
        public void Copy(View v) {

        }

        @Override
        public void SMS(View v) {

        }


        @Override
        public void Email(View v) {
        }
    };
    private UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onResult(SHARE_MEDIA platform) {

            Toast.makeText(WebViewBookedActivity.this, " 分享成功啦", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(WebViewBookedActivity.this, " 分享失败啦", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            if ("QQ".equals(platform.toString())) {
                // Toast.makeText(ShareApplicationActivity.this, " 分享成功啦", Toast.LENGTH_SHORT).show();
            } else {
//                Toast.makeText(WebViewBookedActivity.this, " 分享取消了", Toast.LENGTH_SHORT).show();
            }
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mShareAPI.onActivityResult(requestCode, resultCode, data);
    }

    private void showClassify() {
        relat_classify.setVisibility(View.VISIBLE);
        if (classifylist == null || classifylist.size() == 0) {
            //获取分类数据
            netrequest.requestWypType(1);
        }
    }

    private void dismissClassify() {
        if (relat_classify.getVisibility() == View.VISIBLE) {
            relat_classify.setVisibility(View.GONE);
        }
    }

    @Override
    public void onAfinalFail() {
    }

    @Override
    public void onExecuteSuccess(int requestId, String result, String msg) {
        Log.v("zyl", "请求成功:" + result);
        if (requestId == 1) {
            Log.d("lxp", result);
            try {
                JSONObject jsonObject = new JSONObject(result);
                JSONArray jsonArray = jsonObject.getJSONArray("list");
                for (int i = 0; i < jsonArray.length(); i++) {
                    classifylist.add(jsonArray.getString(i));
                }
                adapter = new BookedClassifyPopAdapter(this, classifylist);
                gridclassify.setAdapter(adapter);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }

    @Override
    public void onExecuteFail(int requestId, String msg) {
        Log.v("zyl", "请求失败:" + msg);
    }

    @Override
    public void onBackPressed() {
        if (relat_classify.getVisibility() == View.VISIBLE) {
            relat_classify.setVisibility(View.GONE);
        } else {
            finish();
        }
    }
}
